package cn.sxt.shop.users.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;

import cn.sxt.common.shop.util.PageInfoUtil;
import cn.sxt.shop.users.dao.IAAdminsTestDao;
import cn.sxt.shop.users.dao.IAGoodsDao;
import cn.sxt.shop.users.dao.IAdminsDao;
import cn.sxt.shop.users.pojo.AAdmins;
import cn.sxt.shop.users.pojo.AAdminsTest;
import cn.sxt.shop.users.pojo.AGoods;
import cn.sxt.shop.users.service.IUsersService;
@Service("usersService")
public class UsersServiceImpl implements IUsersService{

	@Resource
	private IAdminsDao adminsDao;
	@Resource
	private IAAdminsTestDao adminsTestDao;
	@Resource
	private IAGoodsDao goodsDao;
	/*--------------管理员模块开始---------------*/
	@Override
	public AAdmins findOneAdminsService(Map<String, Object> condMap) {
		return this.adminsDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneAdminsService(AAdmins admins) {
		JSONObject resultJson = new JSONObject();
		int n = adminsDao.saveOne(admins);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", admins.getId()+"");
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject updateOneAdminsService(AAdmins admins) {
		JSONObject resultJson = new JSONObject();
		int n = adminsDao.updateOne(admins);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", admins.getId()+"");
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject deleteOneAdminsService(AAdmins admins) {
		JSONObject resultJson = new JSONObject();
		int n = adminsDao.deleteOne(admins);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", admins.getId());
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return null;
	}

	@Override
	public List<AAdmins> findCondListAdminsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		if(pageInfoUtil!=null){
			Page<AAdmins> page = new Page<>(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<AAdmins> adminsList = adminsDao.findCondList(condMap);
			/* 设置总记录数 */
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return adminsList;
		}
		return adminsDao.findCondList(condMap);
	}
	/*--------------管理员模块结束---------------*/
	
	/*--------------管理员模块测试开始---------------*/
	@Override
	public AAdminsTest findOneAdminsTestService(Map<String, Object> condMap) {
		return this.adminsTestDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneAdminsTestService(AAdminsTest adminsTest) {
		JSONObject resultJson = new JSONObject();
		int n = adminsTestDao.saveOne(adminsTest);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", adminsTest.getId()+"");
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject updateOneAdminsTestService(AAdminsTest adminsTest) {
		JSONObject resultJson = new JSONObject();
		int n = adminsTestDao.updateOne(adminsTest);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", adminsTest.getId()+"");
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject deleteOneAdminsTestService(AAdminsTest adminsTest) {
		JSONObject resultJson = new JSONObject();
		int n = adminsTestDao.deleteOne(adminsTest);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", adminsTest.getId());
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return null;
	}

	@Override
	public List<AAdminsTest> findCondListAdminsTestService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		if(pageInfoUtil!=null){
			Page<AAdminsTest> page = new Page<>(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<AAdminsTest> adminsTestList = adminsTestDao.findCondList(condMap);
			/* 设置总记录数 */
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return adminsTestList;
		}
		return adminsTestDao.findCondList(condMap);
	}
	/*--------------管理员模块测试结束---------------*/
	
	/*--------------商品模块测试开始---------------*/
	@Override
	public AGoods findOneGoodsService(Map<String, Object> condMap) {
		return this.goodsDao.findOne(condMap);
	}

	@Override
	public JSONObject saveOneGoodsService(AGoods goods) {
		JSONObject resultJson = new JSONObject();
		int n = goodsDao.saveOne(goods);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", goods.getId()+"");
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject updateOneGoodsService(AGoods goods) {
		JSONObject resultJson = new JSONObject();
		int n = goodsDao.updateOne(goods);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", goods.getId()+"");
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return resultJson;
	}

	@Override
	public JSONObject deleteOneGoodsService(AGoods goods) {
		JSONObject resultJson = new JSONObject();
		int n = goodsDao.deleteOne(goods);
		if(n>0){
			/* 存储结果 */
			JSONObject dataJson = new JSONObject();
			dataJson.put("id", goods.getId());
			dataJson.put("effectCount", n);
			resultJson.put("data", dataJson);
			resultJson.put("code", "1");
			resultJson.put("info", "成功");
		}else{
			resultJson.put("code", "0");
			resultJson.put("info", "失败");
		}
		return null;
	}

	@Override
	public List<AGoods> findCondListGoodsService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap) {
		if(pageInfoUtil!=null){
			Page<AGoods> page = new Page<>(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<AGoods> goodsList = goodsDao.findCondList(condMap);
			/* 设置总记录数 */
			pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal()+""));
			return goodsList;
		}
		return goodsDao.findCondList(condMap);
	}
	/*--------------商品模块测试结束---------------*/
}
